  <?php
    //$param = Layout::getParams();
    //$count_param = count($param) - 1;
    //   if($count_param=="1"){
    //          echo '<br/>';
    //          echo '<br/>';
    //          echo '<br/>';
    //        /*  echo '<h1>' . ucfirst($param[0]) . '</h1>';*/
    //   }elseif($count_param=="2"){
    //          echo '<h1>' . ucfirst($param[1]) . '</h1>';
    //   }elseif($count_param=="3"){
    //          echo '<h1>' . ucfirst($param[2]) . '</h1>';
    //   }else{
    //          echo '<h1>' . ucfirst($param[2]) . '</h1>';
    //   }
  $auth = Auth::getAuth('current_user');
  $db = new Database();
  $company_id = $auth['company_id'];
  $search = new Search();
  $ctrPortal = 0;
  $ret = "";
      // get category that are using
      $forms_array = $db->query("SELECT ws.form_name as form_name, ws.id as id, ws.form_json as form_json
                                          FROM tb_workspace ws
                                          LEFT JOIN tbworkflow wf on ws.id = wf.form_id
                                          WHERE wf.is_active = 1 and ws.is_active = 1
                                          AND company_id = {$db->escape($auth[company_id])}
                                          ORDER BY ws.form_name DESC","array");

      $array_categoryID = array();
      foreach ($forms_array as $forms) {
                
        $json =  json_decode($forms['form_json'],true);
        $formID = $forms['id'];
        $formName = $forms['form_name'];
        $forms = $json['form_json'];
        $categoryID = $json['categoryName'];
        
       array_push($array_categoryID,$categoryID);
     }
      $getcategory = $db->query("SELECT * FROM tbform_category WHERE company_id = $company_id","array");
      foreach($getcategory as $category){
        if($category['users']!=""){
          if($search->getFormPrivacyUsers($category['users'])==false){
            continue;
          }   
        }
        if(in_array($category['id'],$array_categoryID)){
          $cssID = $category['image'];
          if($cssID==""){
            $cssID = "othersportal-icon";
          }
          $ctrPortal++;
          $ret.='<li id="'. $cssID .'">
                 <div class="fl-app-btn">
                    <span>'. $category['category_name'] .'</span><Br/>
                    <span><a href="/user_view" class="setCategory" data-id="'. $category['id'] .'">Use This App</a></span>
                 </div>
              </li>';
        }
      }
      ?>
      <!-- For No Form Category -->
      <?php
        if(in_array("0",$array_categoryID)){   
          $ctrPortal++;
          $ret.='<li id="othersportal-icon">
               <div class="fl-app-btn">
                  <span>Others</span><Br/>
                  <span><a href="/user_view" class="setCategory" data-id="0">Use This App</a></span>
               </div>
            </li>';
        }
  ?>
  <?php
    if($ctrPortal>0){
      echo '<h1 style="text-align:center;">Application Portal</h1>';
    }
  ?>
  
  <center><div class="tour_application" style="text-align: center;width: 10%;"></div></center>
  <br/><br/><br/>
<div class="fl-app-portal-wrapper">
    <div align="center">
    <ul id="portal-app">
      <!-- <li id="hrportal-icon">
         <div class="fl-app-btn">
            <span>Human Resources Application</span><Br/>
            <span><a href="#">Use This App</a></span>
         </div>
      </li>
      <li id="acctportal-icon">
        <div class="fl-app-btn">
            <span>Accounting Application</span><Br/>
            <span><a href="#">Use This App</a></span>
         </div>
      </li>
      <li id="inventoryportal-icon">
         <div class="fl-app-btn">
            <span>Inventory Application</span><Br/>
            <span><a href="#">Use This App</a></span>
         </div>
      </li> -->
      <?php
        echo $ret;
      ?>
      <div class="clearfix"></div>
    </ul>
    <?php
    if($ctrPortal==0){
      echo "<div style='color: #555454;font-size: 20px;line-height: 30px;'>You do not have any application.<br /> For more information please contact your administrator, Thank you!</div>";
    }
    ?>
  </div>
</div>
